import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
Vue.use(VueRouter)

const routes = [{
        path: '/',
        name: 'Home',
        component: Home
    },
    {
        path: "/cart",
        name: "cart",
        component: () =>
            import ("../views/Cart.vue"),
    },
    {
        path: "/fu",
        name: "fu",
        component: () =>
            import ("../views/Fu.vue")
    },
    {
        path: "/my",
        name: "my",
        // beforeEnter: (to, from, next) => {
        //     // ...
        // },
        component: () =>
            import ("../views/My.vue"),
        children: [{
            path: "login",
            name: "login",
            component: () =>
                import ("../views/Login.vue")
        }, {
            path: "reg",
            name: "reg",
            component: () =>
                import ("../views/Reg.vue")
        }]
    },
    {
        path: "/list",
        name: "list",
        component: () =>
            import ("../views/List.vue"),
        meta: {
            keepAlive: true
        }
    },
    {
        path: '/about',
        name: 'About',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () =>
            import ( /* webpackChunkName: "about" */ '../views/About.vue')
    }
]

const router = new VueRouter({
    mode: 'history', //hash模式 和history模式的区别  hash 模式地址栏带#号  基于window.onhashchange事件
    //切换组件。history 基于html5新增的history.pushState 去切换组件
    base: process.env.BASE_URL, // 基本路径   process.env 当前环境
    routes
})


export default router